<style>
    .deptall{cursor: pointer;}
    .xuanding{background-color: #f0f6ff;color: #0079fe}
    .dtree-icon-weibiaoti5{color: #f6b918}
    .dtree-icon-dian{color: #FFFFFF!important;}
    .dtree-nav-item{padding-left: 10px!important;}
    .dtree-nav-show{margin-left: 6px;}
    /*.dtree-nav-div{overflow: hidden;white-space: nowrap;text-overflow: ellipsis;}*/
    .dtree-nav-div{padding-top: 6px;padding-bottom: 6px;line-height: 18px}
</style>
<div class="layui-col-md3" id="engindao">
    <div class="engindao_bac">
        <div style="height: 50px;line-height: 50px;width: 120px;float: left">
            <a class="deptall deptmovedown" dtree-id="deptTree" dtree-menu="moveDown" style="margin-left: 15px">展开</a>
            <a class="deptall deptmoveup" dtree-id="deptTree" dtree-menu="moveUp" style="margin-left: 15px">收起</a>
        </div>
        <div style="width: calc(100% - 120px);float: left">
            <input type="text" id="deptkeyword" onkeydown="keyTableSearch()" style="height: 30px;width: calc(100% - 40px);float: left;margin-top: 10px" placeholder="输入文件夹名称" autocomplete="off" class="layui-input">
            <button style="height: 30px;line-height: 30px;padding: 0 4px;float: left;margin-top: 10px" type="button" id="deptseabutton" class="layui-btn"><i class="layui-icon layui-icon-search"></i></button>
        </div>
        <div style="clear: both"></div>
        <div class="engindao_div" style="background-color: #f5f5f5;width: calc(100% - 20px);margin-left: 10px;border-radius: 5px">
            <div class="engindao_title"><b>文件夹</b></div>
            <div class="engindao_nav">
                <a id="engindao_left"><i class="layui-icon layui-icon-left"></i></a>
            </div>
        </div>
        <div style="overflow: auto;padding-right: 10px" id="deptToolbarDiv">
            <ul id="deptTree" class="dtree" data-id="0"></ul>
        </div>
    </div>
</div>
<div class="layui-col-md2 layui-hide" id="engindaomin">
    <div class="engindao_bg">
        <div class="col" id="engindao_right"><a><i class="layui-icon layui-icon-right"></i></a></div>
        <div class="engindao_title">文件夹</div>
    </div>
</div>
<script>

    var pubbaninfo;
    var pub_muArr;

    var param_enginid = getQueryVariable('id') || 0;

    $("#engindao #engindao_left").click(function () {
        var cliHeight = document.getElementById('engindao').clientHeight;

        $("#engindao").addClass('layui-hide');
        $("#table-card #table_list").addClass('engindaomin_guan');

        document.getElementById('engindaomin').style.height = cliHeight+"px";
        $("#engindaomin").removeClass('layui-hide');
    });
    $("#engindaomin #engindao_right").click(function () {
        $("#engindao").removeClass('layui-hide');
        $("#table-card #table_list").removeClass('engindaomin_guan');
        $("#engindaomin").addClass('layui-hide');
    });


    get_mu_info();

    function get_mu_info(muid=0) {
        layui.use(['dtree','layer','jquery','form','laytp','table','dropdown'],function() {
            var dtree = layui.dtree, layer = layui.layer, $ = layui.jquery, form = layui.form, table = layui.table;
            DeptTree = dtree.render({
                elem: "#deptTree",
                url: server_api_name+ask_enginbao_mu_list,
                request: {haveshen:1,token: facade.getCookie('token'),enginid:param_enginid,muid:muid},
                width: '100%',
                height: document.documentElement.clientHeight*0.75-60,
                line: true,
                skin: "zdy",
                initLevel: 2,
                nodeIconArray:[
                    {"open": "dtree-icon-weibiaoti5", "close": "dtree-icon-weibiaoti5"},	//文件夹(二级图标默认样式)
                ],
                scroll:"#deptToolbarDiv",
                toolbarShow:[],
                menubar:true,
                menubarTips:{group:[]},
                success: function(data, obj, first){
                    user_token_roletype = data.token_roletype;

                    butauth = data.bao_butauth;
                    if(check_caoauth('chuanbao')){
                        $("#but_chuanbao").removeClass('butmenuhide');
                    }else{
                        $("#but_chuanbao").addClass('butmenuhide');
                    }


                    if(data.bonum > 0){
                        $("#curmsg").removeClass('layui-hide');
                        $("#curmsg #bonum").html(data.bonum);
                    }else{
                        $("#curmsg").addClass('layui-hide');
                        $("#curmsg #bonum").html(0);
                    }



                    pub_muArr = getIdByChildren(data.data, []);
                    if(muid){
                        choose_muid(muid)
                    }else{
                        setWenList(data.data[0].basicData)
                        $("#muid").val(data.data[0].basicData.id)
                        $("#muid_name").val(data.data[0].basicData.parentsName)
                        setTimeout(function () {
                            $(".dtree-nav-div[data-id='"+data.data[0].basicData.id+"']").addClass('xuanding');
                        },100)
                    }
                }
            });
            //左键单击事件
            dtree.on("node('deptTree')" ,function(obj){
                $(".dtree-nav-div").removeClass('xuanding');
                $(obj.dom).addClass('xuanding');

                setWenList(obj.param.basicData)
            });

            dtree.on("nodedblclick('deptTree')" ,function(obj){
                pubbaninfo = obj.param.basicData;
                if(pubbaninfo .ismu > 0){
                    openPage('tan_info.php', '80%', '80%');
                }
            });

            //搜索部门
            $("#deptseabutton").click(function(){
                var keyword = $("#deptkeyword").val();
                DeptTree.fuzzySearch(keyword);
            });

        });
    }

    function keyTableSearch() {
        if (event.keyCode == 13) {
            var keyword = $("#deptkeyword").val();
            DeptTree.fuzzySearch(keyword);
        }
    }



    function getIdByChildren(data, Arr) {
        for (var key in data){
            if(data[key].basicData){
                Arr.push(data[key].basicData);
            }
            if(data[key].children){
                getIdByChildren(data[key].children, Arr);
            }
        }
        return Arr;
    }


    function choose_muid(muid) {
        for (var key in pub_muArr) {
            if(pub_muArr[key].id == muid){
                setWenList(pub_muArr[key])
                $("#muid").val(pub_muArr[key].id)
                $("#muid_name").val(pub_muArr[key].parentsName)
            }
        }
        $(".dtree-nav-div").removeClass('xuanding');
        setTimeout(function () {
            $(".dtree-nav-div[data-id='"+muid+"']").addClass('xuanding');
        },100)
    }


    function check_caoauth(butname) {
        var res = false;
        for(var key in butauth){
            if(butauth[key].butname == butname){
                res = true;
            }
        }
        return res;
    }
</script>
